package com.business.api.official.toursism.websitenews.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.api.official.toursism.websitenews.manager.WebsiteNewsApiManager;
import com.business.api.official.toursism.websitenews.mapper.WebsiteNewsApiMapper;
import com.business.api.official.toursism.websitenews.vo.WebsiteNewsApiBriefListVO;
import com.business.api.official.toursism.websitenews.vo.WebsiteNewsApiBriefVO;
import com.business.api.official.toursism.websitenews.vo.WebsiteNewsApiDetailListVO;
import com.business.api.official.toursism.websitenews.vo.WebsiteNewsApiDetailVO;
import com.business.api.official.toursism.websitenews.vo.data.WebsiteNewsApiBriefData;
import com.business.api.official.toursism.websitenews.vo.data.WebsiteNewsApiDetailData;
import com.business.system.official.toursism.websitenews.entity.WebsiteNews;
import com.business.system.official.toursism.websitenews.manager.WebsiteNewsManager;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedApiManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 乌镇新闻
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Service("websiteNewsApiManager")
@Transactional(rollbackFor = ManagerException.class)
public class WebsiteNewsApiManagerImpl extends SeedApiManagerImpl<WebsiteNewsApiMapper, WebsiteNews> implements WebsiteNewsApiManager {
    @Autowired
    private WebsiteNewsManager systemManager;

    /**
     * 根据id获取详情VO data
     *
     * @param websiteNewsId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailData convertApiDetailData(String websiteNewsId) throws ManagerException {
        WebsiteNews websiteNews = this.getById(websiteNewsId);
        return this.convertApiDetailData(websiteNews);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNews model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailData convertApiDetailData(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsApiDetailData websiteNewsApiDetailData = new WebsiteNewsApiDetailData();
        try {
            BeanUtils.copyProperties(websiteNews, websiteNewsApiDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteNews);
        }
        return websiteNewsApiDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteNewsId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailVO getApiDetailVO(String websiteNewsId) throws ManagerException {
        WebsiteNewsApiDetailData websiteNewsApiDetailData = this.convertApiDetailData(websiteNewsId);
        return new WebsiteNewsApiDetailVO(websiteNewsApiDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteNews 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailVO getApiDetailVO(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsApiDetailData websiteNewsApiDetailData = this.convertApiDetailData(websiteNews);
        return new WebsiteNewsApiDetailVO(websiteNewsApiDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiDetailData> getConvertApiDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertApiDetailData(websiteNewsList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiDetailData> listConvertApiDetailData(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertApiDetailData(websiteNewsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNewsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiDetailData> listConvertApiDetailData(List<WebsiteNews> websiteNewsList) throws ManagerException {
        List<WebsiteNewsApiDetailData> websiteNewsApiDetailDataList = new ArrayList<>();
        for (WebsiteNews websiteNews : websiteNewsList) {
            websiteNewsApiDetailDataList.add(this.convertApiDetailData(websiteNews));
        }
        return websiteNewsApiDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailListVO getApiDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteNewsApiDetailListVO(this.getConvertApiDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailListVO getApiDetailListVO(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        return new WebsiteNewsApiDetailListVO(this.listConvertApiDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteNewsList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiDetailListVO getApiDetailListVO(List<WebsiteNews> websiteNewsList) throws ManagerException {
        return new WebsiteNewsApiDetailListVO(this.listConvertApiDetailData(websiteNewsList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteNewsId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefData convertApiBriefData(String websiteNewsId) throws ManagerException {
        WebsiteNews websiteNews = this.getById(websiteNewsId);
        return this.convertApiBriefData(websiteNews);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNews model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefData convertApiBriefData(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsApiBriefData websiteNewsApiBriefData = new WebsiteNewsApiBriefData();
        try {
            BeanUtils.copyProperties(websiteNews, websiteNewsApiBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteNews);
        }
        return websiteNewsApiBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteNewsId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefVO getApiBriefVO(String websiteNewsId) throws ManagerException {
        WebsiteNewsApiBriefData websiteNewsApiBriefData = this.convertApiBriefData(websiteNewsId);
        return new WebsiteNewsApiBriefVO(websiteNewsApiBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteNews 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefVO getApiBriefVO(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsApiBriefData websiteNewsApiBriefData = this.convertApiBriefData(websiteNews);
        return new WebsiteNewsApiBriefVO(websiteNewsApiBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiBriefData> listConvertApiBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertApiBriefData(websiteNewsList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiBriefData> listConvertApiBriefData(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertApiBriefData(websiteNewsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNewsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiBriefData> listConvertApiBriefData(List<WebsiteNews> websiteNewsList) throws ManagerException {
        List<WebsiteNewsApiBriefData> websiteNewsApiBriefDataList = new ArrayList<>();
        for (WebsiteNews websiteNews : websiteNewsList) {
            websiteNewsApiBriefDataList.add(this.convertApiBriefData(websiteNews));
        }
        return websiteNewsApiBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefListVO getApiBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return new WebsiteNewsApiBriefListVO(this.listConvertApiBriefData(websiteNewsList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefListVO getApiBriefListVO(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return new WebsiteNewsApiBriefListVO(this.listConvertApiBriefData(websiteNewsList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteNewsList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsApiBriefListVO getApiBriefListVO(List<WebsiteNews> websiteNewsList) throws ManagerException {
        return new WebsiteNewsApiBriefListVO(this.listConvertApiBriefData(websiteNewsList));
    }

    /**
     * 根据对象list获取模糊查询VO data list
     *
     * @param websiteNewsList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsApiDetailData> listConvertApiTitleData(List<WebsiteNews> websiteNewsList) throws ManagerException {
        List<WebsiteNewsApiDetailData> list = new ArrayList<>();
        for (WebsiteNews websiteNews : websiteNewsList) {
            list.add(this.convertApiTitleData(websiteNews));
        }
        return list;
    }

    private WebsiteNewsApiDetailData convertApiTitleData(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsApiDetailData websiteNewsApiBriefData = new WebsiteNewsApiDetailData();
        try {
            BeanUtils.copyProperties(websiteNews, websiteNewsApiBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteNews);
        }
        return websiteNewsApiBriefData;
    }
}